<template>
  <div class="goodsList-box">
    <!-- 这是商品列表页 -->
    <div class="good-item" v-for="item in goodsList" :key="item.id">
      <img :src="item.img_url">
      <h3>{{item.title}}</h3>
      <div class="info">
        <p class="price">
          <span class="new">￥{{item.sell_price}}</span>
          <span class="old">${{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
  </div>
</template>
<script>
import { toast } from "mint-ui";
export default {
  data() {
    return {
      pageindex: 1,
      goodsList: []
    };
  },
  created() {
    this.getgoodsList();
  },
  methods: {
    getgoodsList() {
      this.$http.get("api/getgoods?pageindex=" + this.pageindex).then(res => {
        var res = res.body;
        if (res.status === 0) {
          this.goodsList = res.message;
        } else {
          toast("获取失败");
        }
      });
    },
    getMore(){
        this.pageindex +=1
        this.getgoodsList()
    }
  }
};
</script>
<style lang="scss" scoped>
.goodsList-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 7px;
  .good-item {
    border: 1px solid #ccc;
    width: 49%;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    max-height: 293px;
    h3 {
      font-size: 14px;
    }
    .info {
        background-color: #eee;
        p{
            margin: 0;
            padding: 5px;
        }
      .price {
        .new {
          font-size: 16px;
          color: red;
        }
        .old {
          margin-left: 10px;
          font-size: 12px;
          text-decoration: line-through;
          color: #ccc;
        }
      }
      .sell {
          display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }

    img {
      text-align: center;
      width: 100%;
    }
  }
}
</style>